package servletlearn.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "IndexServlet", urlPatterns = "/iServlet")
public class IndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        request.getSession();
        PrintWriter out = response.getWriter();
        String url1 = response.encodeURL("/ZY/s1Servlet");//浏览器阻止cookie时用这个
        String url2 = response.encodeURL("/ZY/s2Servlet");
        out.print("<a href=\"" + url1 + "\">购买</a>");
        out.print("<a href=\"" + url2 + "\">结账</a>");
    }
}
